package com.ems.service.impl;

import com.ems.entity.PcsAlarmBitEntity;
import com.ems.mapper.PcsAlarmBitMapper;
import com.ems.service.IPcsAlarmBitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ems.util.SnowflakeIdWorker;
import com.ems.util.StateEnum;
import com.ems.util.StateException;
import com.ems.vo.PcsAlarmBitVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * PCS故障字 服务实现类
 * </p>
 *
 * @author WuZH
 * @since 2024-04-23
 */
@Service
public class PcsAlarmBitServiceImpl extends ServiceImpl<PcsAlarmBitMapper, PcsAlarmBitEntity> implements IPcsAlarmBitService {

    @Resource
    private PcsAlarmBitMapper pcsAlarmBitMapper;

    @Override
    public PcsAlarmBitVo saveSingle ( PcsAlarmBitVo pcsAlarmBitVo ) {
        if ( pcsAlarmBitVo == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        PcsAlarmBitEntity pcsAlarmBitEntity = new PcsAlarmBitEntity ();
        BeanUtils.copyProperties ( pcsAlarmBitVo, pcsAlarmBitEntity );
        pcsAlarmBitEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        pcsAlarmBitEntity.setCreateTime ( new Date () );
        int insert = baseMapper.insert ( pcsAlarmBitEntity );
        if ( insert == 0 ) {
            throw new StateException ( StateEnum.INSERT_EXCE );
        }
        return pcsAlarmBitVo;
    }

    @Override
    public List<PcsAlarmBitVo> queryList ( PcsAlarmBitVo pcsAlarmBitVo ) {
        List<PcsAlarmBitVo> pcsAlarmBitVos = pcsAlarmBitMapper.queryList ( pcsAlarmBitVo );
        return pcsAlarmBitVos;
    }
}
